package com.galen.subscriber.filter;

import com.galen.subscriber.common.Result;
import com.galen.subscriber.filter.chain.CanalFilterChain;
import com.galen.subscriber.common.Result;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

/**
 * @author shuaiys
 * @version 1.0
 * @package com.galen.subscriber.filter
 * @description 订阅自定义库表变化
 * @date 2020-03-05 16:00
 */
@Data
@Slf4j
@Component
public class NzhTablesCanalFilter implements CanalFilter, Ordered {

    @Override
    public Result filter(CanalExchange exchange, CanalFilterChain chain) {
        if (exchange.getDatabase().equals("galen")) {
            log.info("DB: {}, Table: {}, Method: {}, Update Columns: {}, Before Data: {}, After Data: {}",
                    exchange.getDatabase(), exchange.getTableName(), exchange.getEventType(), exchange.getUpdateColumns(), exchange.getBeforeColumns(), exchange.getAfterColumns());

            // 订阅galen库的变化，业务逻辑在这写
        }

        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
